#include <boost/test/unit_test.hpp>
#include <qua/time.h>
#include <qua/io.h>

using namespace qua;

struct time_test_fixture
{
    time_test_fixture()
    {
    }

    ~time_test_fixture()
    {
    }
};

BOOST_FIXTURE_TEST_SUITE( time_test_suite, time_test_fixture )

BOOST_AUTO_TEST_CASE( time_initialize_test_case )
{
    time birth_date( 1983, 12, 22 );
    BOOST_CHECK_EQUAL( birth_date.year(),     1983 );
    BOOST_CHECK_EQUAL( birth_date.month(),      12 );
    BOOST_CHECK_EQUAL( birth_date.day(),        22 );
    BOOST_CHECK_EQUAL( birth_date.hour(),        0 );
    BOOST_CHECK_EQUAL( birth_date.minute(),      0 );
    BOOST_CHECK_EQUAL( birth_date.second(),      0 );
    BOOST_CHECK_EQUAL( birth_date.millisecond(), 0 );
    BOOST_CHECK_EQUAL( birth_date.microsecond(), 0 );

    time some_time( 2012, 12, 20, 21, 02, 00, 2102 );
    BOOST_CHECK_EQUAL( some_time.year(),        2012 );
    BOOST_CHECK_EQUAL( some_time.month(),         12 );
    BOOST_CHECK_EQUAL( some_time.day(),           20 );
    BOOST_CHECK_EQUAL( some_time.hour(),          21 );
    BOOST_CHECK_EQUAL( some_time.minute(),        02 );
    BOOST_CHECK_EQUAL( some_time.second(),         0 );
    BOOST_CHECK_EQUAL( some_time.millisecond(),    2 );
    BOOST_CHECK_EQUAL( some_time.microsecond(), 2102 );

    BOOST_CHECK_NE( birth_date, some_time );
    BOOST_CHECK_LT( birth_date, some_time );
    BOOST_CHECK_LE( birth_date, some_time );
    BOOST_CHECK_GT( some_time, birth_date );
    BOOST_CHECK_GE( some_time, birth_date );
    BOOST_CHECK_EQUAL( birth_date, time( 1983, 12, 22 ) );
    BOOST_CHECK_EQUAL( some_time, time( 2012, 12, 20, 21, 02, 00, 2102 ) );

    time::delta time_delta = some_time - birth_date;
    BOOST_CHECK_EQUAL( time_delta.in_days(),                   10591LL );
    BOOST_CHECK_EQUAL( time_delta.in_hours(),                 254205LL );
    BOOST_CHECK_EQUAL( time_delta.in_minutes(),             15252302LL );
    BOOST_CHECK_EQUAL( time_delta.in_seconds(),            915138120LL );
    BOOST_CHECK_EQUAL( time_delta.in_milliseconds(),    915138120002LL );
    BOOST_CHECK_EQUAL( time_delta.in_microseconds(), 915138120002102LL );

    time::delta custom_delta( days(123), minutes(234), milliseconds(345) );
    BOOST_CHECK_EQUAL( custom_delta.in_days(),                    123LL );
    BOOST_CHECK_EQUAL( custom_delta.in_hours(),                  2955LL );
    BOOST_CHECK_EQUAL( custom_delta.in_minutes(),              177354LL );
    BOOST_CHECK_EQUAL( custom_delta.in_seconds(),            10641240LL );
    BOOST_CHECK_EQUAL( custom_delta.in_milliseconds(),    10641240345LL );
    BOOST_CHECK_EQUAL( custom_delta.in_microseconds(), 10641240345000LL );

    BOOST_CHECK( time_delta != custom_delta );
    BOOST_CHECK( time_delta >  custom_delta );
    BOOST_CHECK( time_delta >= custom_delta );
    BOOST_CHECK( custom_delta <  time_delta );
    BOOST_CHECK( custom_delta <= time_delta );
    BOOST_CHECK( time_delta == time::delta( days(10591), hours(21), minutes(1), seconds(59), milliseconds(1002), microseconds(102) ) );
    BOOST_CHECK( custom_delta == time::delta( days(123), minutes(234), milliseconds(345) ) );
}

BOOST_AUTO_TEST_SUITE_END()
